<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	/*******main*******/
	//路线
	$params1=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'status'=>1,'ishot'=>1);
	$params2=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'ishot'=>1);
	if(!empty($_RQ['keyword'])){
		$params1['title like']='%'.trim($_RQ['keyword']).'%';
		$params2['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=trim($_RQ['keyword']);
	}
	
	$ways=pdo_getall('jy_tour_way',$params1,'','createtime desc limit 6');
	//print_r($params1);exit;
	if($ways){
		foreach($ways as &$item){
			$images=json_decode($item['images'],true);
			$item['thumb']=$images['0'];
			//下单人数
			$item['sum']=pdo_count('jy_tour_order',array('uniacid'=>$_SESSION['uniacid'],'status >'=>0,'way_id'=>$item['id']));
			//好评数量
			$goodnum=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'way_id'=>$item['id'],'star >'=>'3'));
			$item['goodrate']=ceil($goodnum/$item['sum']*100).'%';
			$item['tags']=str_array($item['tags'],'|');
		}
	}
	$spots=pdo_getall('jy_tour_spot',$params2,'','','createtime desc limit 6');
	if($spots){
		foreach($spots as &$item){
			$images=json_decode($item['images'],true);
			$item['thumb']=$images['0'];
			//下单人数
			$item['sum']=pdo_count('jy_tour_order',array('uniacid'=>$_SESSION['uniacid'],'status >'=>0,'spot_id'=>$item['id']));
			//好评数量
			$goodnum=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'spot_id'=>$item['id'],'star >'=>'3'));
			$item['goodrate']=ceil($goodnum/$item['sum']*100).'%';
			$item['tags']=str_array($item['tags'],'|');
		}
	}
	$return['image']=$setting['image'];
	$return['ways']=$ways;
	$return['spots']=$spots;
	//print_r($ways);exit;
	exi($return);
}
if($_RQ['op']=='getlist'){
	$post=get_postdata();
	$params1=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
		'ishot'=>1,
	);
	$params2=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
		'isshenhe'=>1,
		'ishot'=>1,
	);
/*	if(trim($_RQ['keyword'])){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=trim($_RQ['keyword']);
	}
	if($post['province']){
		if($post['city']){
			$params['city']=$post['city'];
			
		}else{
			$params['province']=$post['province'];
		}
	}
	*/
	$psize = 20;
	$total='';
	$fields1=array('id','ishot','images','title');
	$fields2=array('id','isshenhe','images','title');
	$orderby='id desc ';
	$pindex = max(1, intval($post['page']));

	$spots=pdo_getslice('jy_tour_spot',$params1,array($pindex,$psize),$total,$fields1,'',$orderby);
	$ways=pdo_getslice('jy_tour_ways',$params2,array($pindex,$psize),$total,$fields2,'',$orderby);
	if(!$spots){
		exi('none');
	}
	if($spots){
		foreach($spots as &$item){
			$images=json_decode($item['images'],true);
			$item['thumb']=$images['0'];
		}
	}
	$return['list']=$list;
	exi($return);
}